package com.weiyi.mashangzhu.Roomer.Activity;

import android.Manifest;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.Text;
import com.google.gson.Gson;
import com.squareup.okhttp.Request;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.Application.MyApp;
import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Adapter.GridAdapter_Price;
import com.weiyi.mashangzhu.Roomer.Adapter.GridAdapter_Type;
import com.weiyi.mashangzhu.Roomer.Bean.PriceBean;
import com.weiyi.mashangzhu.Utils.GlideImgManager;
import com.weiyi.mashangzhu.Utils.LoadingDialog;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.Utils.T;
import com.weiyi.mashangzhu.Utils.UiUtil;
import com.weiyi.mashangzhu.Weight.calendartest.MonthTimeAdapter;
import com.weiyi.mashangzhu.Weight.calendartest.entity.DayTimeEntity;
import com.weiyi.mashangzhu.Weight.calendartest.entity.MonthTimeEntity;
import com.weiyi.mashangzhu.Weight.calendartest.entity.UpdataCalendar;
import com.weiyi.mashangzhu.Weight.calendartest.utils.SharePreferences;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;


import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;


public class SearchActivity extends BaseActivity {


    @BindView(R.id.search_address)
    TextView searchAddress;
    @BindView(R.id.search_location_value)
    TextView searchLocationValue;
    @BindView(R.id.search_location)
    RelativeLayout searchLocation;
    @BindView(R.id.search_date)
    TextView searchDate;
    @BindView(R.id.search_site)
    TextView searchSite;
    @BindView(R.id.search_price)
    TextView searchPrice;
    @BindView(R.id.search_seek)
    Button searchSeek;
    @BindView(R.id.search_root)
    LinearLayout searchRoot;
    private TextView startTime;          //开始时间
    private TextView stopTime;           //结束时间

    private RecyclerView reycycler;
    private MonthTimeAdapter adapter;
    private ArrayList<MonthTimeEntity> datas;


    public static DayTimeEntity startDay;
    public static DayTimeEntity stopDay;

    SharePreferences isPreferences;
    String po1, po2 = "";
    String city = "";
    public LocationClient mLocationClient = null;
    String price;
    String types[];
    List<String> types_select = new ArrayList<>();
    String latitude, longitude;
    String type_num = "";

    public BDAbstractLocationListener myListener = new MyLocationListener();
    String[] permissions = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.READ_PHONE_STATE};

    @Override
    public void finish() {
        super.finish();
        MyApp.search_price=-1;
        MyApp.search_type.clear();
//        Log.e("mmmmmmmmmm","finish");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        ButterKnife.bind(this);
        MyApp.search_price=0;
        isPreferences = new SharePreferences(this);
        EventBus.getDefault().register(this);
        mLocationClient = new LocationClient(getApplicationContext());
        //声明LocationClient类
        mLocationClient.registerLocationListener(myListener);
        //注册监听函数
        initLocation();

    }


    private void initData(final PopupWindow popupWindow) {
        startDay = new DayTimeEntity(0, 0, 0, 0);
        stopDay = new DayTimeEntity(-1, -1, -1, -1);
        datas = new ArrayList<>();

        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;

        datas.add(new MonthTimeEntity(year, month));                //

        for (int i = 0; i < 6; i++) {
            MonthTimeEntity monthTimeEntity = new MonthTimeEntity();
            if (month >= 12) {//明年
                year = c.get(Calendar.YEAR) + 1;
                month = 1;
                monthTimeEntity.setYear(year);
                monthTimeEntity.setMonth(month);
            } else {
                month = month + 1;
                monthTimeEntity.setYear(year);
                monthTimeEntity.setMonth(month);
            }

            datas.add(monthTimeEntity);

        }

        adapter = new MonthTimeAdapter(datas, SearchActivity.this);
        reycycler.setAdapter(adapter);

        adapter.setOnDayItemClickListener(new MonthTimeAdapter.OnDayItemClickListener() {
            @Override
            public void OnDayItemClick(View view, int position) {
                isPreferences.updateSp("start_month_position", startDay.getMonthPosition());
                isPreferences.updateSp("start_day_position", startDay.getDayPosition());
                isPreferences.updateSp("end_month_position", stopDay.getMonthPosition());
                isPreferences.updateSp("end_day_position", stopDay.getDayPosition());

                isPreferences.updateSp("start_year", startDay.getYear());
                isPreferences.updateSp("start_month", startDay.getMonth());
                isPreferences.updateSp("start_day", startDay.getDay());

                isPreferences.updateSp("end_year", stopDay.getYear());
                isPreferences.updateSp("end_month", stopDay.getMonth());
                isPreferences.updateSp("end_day", stopDay.getDay());


                Intent i = new Intent();
                i.putExtra("start_year", startDay.getYear());
                i.putExtra("start_month", startDay.getMonth());
                i.putExtra("start_day", startDay.getDay());

                i.putExtra("end_year", stopDay.getYear());
                i.putExtra("end_month", stopDay.getMonth());
                i.putExtra("end_day", stopDay.getDay());
                setResult(RESULT_OK, i);
                MyApp.starttime_xuan = startDay.getYear() + "-" + startDay.getMonth() + "-" + startDay.getDay();
                MyApp.endtime_xuan = stopDay.getYear() + "-" + stopDay.getMonth() + "-" + stopDay.getDay();
                searchDate.setText(startDay.getYear() + "-" + startDay.getMonth() + "-" + startDay.getDay() + "/" + stopDay.getYear() + "-" + stopDay.getMonth() + "-" + stopDay.getDay());
                popupWindow.dismiss();

            }
        });

    }

    public void showPopupWindow() {
        View contentView = LayoutInflater.from(this).inflate(R.layout.pop_win_date, null);
        final PopupWindow popupWindow = new PopupWindow(contentView,
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);


        startTime = (TextView) contentView.findViewById(R.id.plan_time_txt_start);
        stopTime = (TextView) contentView.findViewById(R.id.plan_time_txt_stop);
        ImageView close = (ImageView) contentView.findViewById(R.id.close);
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        reycycler = (RecyclerView) contentView.findViewById(R.id.plan_time_calender);
        LinearLayoutManager layoutManager =
                new LinearLayoutManager(this,   // 上下文
                        LinearLayout.VERTICAL,  //垂直布局,
                        false);

        reycycler.setLayoutManager(layoutManager);

        MoveToPosition(layoutManager, reycycler, isPreferences.getSp().getInt("start_month_position", 0));


        popupWindow.setTouchable(true);
        popupWindow.setAnimationStyle(R.style.popup_window_bottom_animation);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x55000000));
        // 设置好参数之后再show
        popupWindow.showAtLocation(contentView, Gravity.CENTER, 0, 0);
        initData(popupWindow);

    }

    public void showPricePopupWindow() {
        OkHttpUtils.post().addParams("token", SPUtils.get(this, "token", "") + "").url(API.BaseApi_R + API.SearchPrice_Api).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
                T.showShort(SearchActivity.this, "网络连接失败，请检查一下网络设置");
            }

            @Override
            public void onResponse(String response) {
                Log.e("ppppppppp", "=" + response);
                PriceBean priceBean = new Gson().fromJson(response, PriceBean.class);
                List<PriceBean.DataBean.TypelistBean> typelistBeanList = priceBean.getData().getTypelist();
                final List<String> pricelist = priceBean.getData().getPricelis();
                final List<String> typelist = new ArrayList<String>();
                for (int i = 0; i < typelistBeanList.size(); i++) {
                    typelist.add(typelistBeanList.get(i).getTName() + "");
                }
                price = pricelist.get(0);
                types = new String[typelist.size()];
                if (MyApp.search_type!=null&&MyApp.search_type.size()!=0){
                    for (int i = 0; i < types.length; i++) {
                        types[i] = "no";
                    }
                    for (int i = 0; i <MyApp.search_type.size() ; i++) {
                        types[Integer.parseInt(MyApp.search_type.get(i))]="yes";
                    }
                }else {
                    if (types.length > 0) {
                        types[0] = "yes";
                        if (types.length > 1) {
                            for (int i = 1; i < types.length; i++) {
                                types[i] = "no";
                            }
                        }
                    }
                }



                View contentView = LayoutInflater.from(SearchActivity.this).inflate(R.layout.pop_win_price, null);
                final PopupWindow popupWindow = new PopupWindow(contentView,
                        LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
                final GridView gridView = (GridView) contentView.findViewById(R.id.gridview);
                final GridView gridView_type = (GridView) contentView.findViewById(R.id.gridview_type);
                Button btn = (Button) contentView.findViewById(R.id.btn);
                gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        TextView textview = (TextView) gridView.getChildAt(position).findViewById(R.id.tv);
                        textview.setTextColor(getResources().getColor(R.color.colorPrimary));
                        textview.setBackground(getResources().getDrawable(R.drawable.shape_blue_line_bg));
                        price = textview.getText() + "";

                        for (int i = 0; i < position; i++) {
                            TextView textview2 = (TextView) gridView.getChildAt(i).findViewById(R.id.tv);
                            textview2.setTextColor(getResources().getColor(R.color.colorText));
                            textview2.setBackground(getResources().getDrawable(R.drawable.shape_light_line_bg));
                        }
                        for (int i = position + 1; i < pricelist.size(); i++) {
                            TextView textview3 = (TextView) gridView.getChildAt(i).findViewById(R.id.tv);
                            textview3.setTextColor(getResources().getColor(R.color.colorText));
                            textview3.setBackground(getResources().getDrawable(R.drawable.shape_light_line_bg));
                        }
                    }
                });
                gridView_type.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        if (types[position].equals("no")) {
                            TextView textview = (TextView) gridView_type.getChildAt(position).findViewById(R.id.tv);
                            textview.setTextColor(getResources().getColor(R.color.colorPrimary));
                            textview.setBackground(getResources().getDrawable(R.drawable.shape_blue_line_bg));
                            types[position] = "yes";
                        } else {
                            TextView textview2 = (TextView) gridView_type.getChildAt(position).findViewById(R.id.tv);
                            textview2.setTextColor(getResources().getColor(R.color.colorText));
                            textview2.setBackground(getResources().getDrawable(R.drawable.shape_light_line_bg));
                            types[position] = "no";
                        }
                    }
                });

                gridView.setAdapter(new GridAdapter_Price(SearchActivity.this, R.layout.item_grid, pricelist));
                gridView_type.setAdapter(new GridAdapter_Type(SearchActivity.this, R.layout.item_grid, typelist));
                btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        type_num = "";
                        popupWindow.dismiss();
                        List<String> aa = new ArrayList<String>();
                        String type = "";
                        types_select.clear();
                        for (int i = 0; i < types.length; i++) {
                            if (types[i].equals("yes")) {
                                types_select.add("" + i);
                                aa.add(typelist.get(i));
                            }
                        }
                        MyApp.search_type=types_select;
                        type_num = "";
                        for (int j = 0; j < types_select.size(); j++) {
                            if (j != types_select.size() - 1) {
                                type_num += Integer.valueOf(types_select.get(j)) + 1 + ",";
                            } else {
                                type_num += Integer.valueOf(types_select.get(j)) + 1;
                            }
                        }
                        for (int i = 0; i < aa.size(); i++) {
                            if (i != aa.size() - 1) {
                                type += aa.get(i) + "/";
                            } else {
                                type += aa.get(i);
                            }
                        }
                        searchPrice.setText(price + "/" + type);
                        if (price.equals("150以下")) {
                            MyApp.search_price = 0;
                        } else if (price.equals("150-300")) {
                            MyApp.search_price = 1;
                        } else if (price.equals("300-500")) {
                            MyApp.search_price = 2;
                        } else if (price.equals("500以上")) {
                            MyApp.search_price = 3;
                        }
                    }
                });

                popupWindow.setTouchable(true);
                popupWindow.setAnimationStyle(R.style.popup_window_bottom_animation);
                popupWindow.setBackgroundDrawable(new ColorDrawable(0x55000000));
                // 设置好参数之后再show
                popupWindow.showAtLocation(contentView, Gravity.CENTER, 0, 0);
            }
        });


    }

    //直接显示第n个item内容
    public static void MoveToPosition(LinearLayoutManager manager, RecyclerView mRecyclerView, int n) {
        int firstItem = manager.findFirstVisibleItemPosition();
        int lastItem = manager.findLastVisibleItemPosition();
        if (n <= firstItem) {
            mRecyclerView.scrollToPosition(n);
        } else if (n <= lastItem) {
            int top = mRecyclerView.getChildAt(n - firstItem).getTop();
            mRecyclerView.scrollBy(0, top);
        } else {
            mRecyclerView.scrollToPosition(n);
        }

    }

    public void onEventMainThread(UpdataCalendar event) {
        adapter.notifyDataSetChanged();
        startTime.setText(startDay.getMonth() + "月" + startDay.getDay() + "日" + "\n");
        if (stopDay.getDay() == -1) {
            stopTime.setText("结束" + "\n" + "时间");
        } else {
            stopTime.setText(stopDay.getMonth() + "月" + stopDay.getDay() + "日" + "\n");
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
            if (resultCode == 1) {
                city = data.getStringExtra("city");
                searchAddress.setText(city);
                searchLocationValue.setTextColor(getResources().getColor(R.color.light_gray));
                Drawable topDrawable = getResources().getDrawable(R.mipmap.my);
                topDrawable.setBounds(0, 0, topDrawable.getMinimumWidth(), topDrawable.getMinimumHeight());
                searchLocationValue.setCompoundDrawables(null, topDrawable, null, null);

            } else if (resultCode == 2) {
                searchSite.setText(data.getStringExtra("select"));
            }
        }

    }

    @OnClick({R.id.back, R.id.search_address, R.id.search_location, R.id.search_date, R.id.search_site, R.id.search_price, R.id.search_seek, R.id.search_location_value})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.search_address:

                startActivityForResult(new Intent(this, CitySelectActivity.class),
                        0);
                break;
            case R.id.search_date:
                if (city == null || city.equals("")) {
                    T.showShort(SearchActivity.this, "请选择目的地或定位位置"); // 正在定位你的位置，请稍后
                } else {
                    showPopupWindow();
                }
                break;
            case R.id.search_site:
                if (city == null || city.equals("") /*|| (searchAddress.getText() + "").equals("我的附近")*/) {
                    T.showShort(SearchActivity.this,  "请选择目的地或定位位置");
                } else {
                    Intent intent = new Intent(this, LandMarkActivity.class);
                    intent.putExtra("city", city);
                    startActivityForResult(intent, 0);
                }
                break;
            case R.id.search_price:
                if (city == null || city.equals("")) {
                    T.showShort(SearchActivity.this, "请选择目的地或定位位置");
                } else {
                    showPricePopupWindow();
                }
                break;
            case R.id.search_seek:
                if (city == null || city.equals("")) {
                    T.showShort(SearchActivity.this,  "请选择目的地或定位位置");
                } else {
                    Intent intent = new Intent(this, SearchListActivity.class);
                    if ((searchAddress.getText() + "").equals("选择目的地")) {

                    } else if ((searchAddress.getText() + "").equals("我的附近")) {
                        intent.putExtra("city", latitude + "," + longitude + "," + city);

                    } else {
                        intent.putExtra("city", searchAddress.getText() + "");
                    }
                    if (!(searchDate.getText()).equals("选择入住离开日期")) {
                        String[] date = (searchDate.getText() + "").split("/");
                        intent.putExtra("starttime", date[0]);
                        intent.putExtra("endtime", date[1]);

                    }
                    if (!(searchSite.getText() + "").equals("地标/房东昵称/房源标题")) {
                        intent.putExtra("site", searchSite.getText() + "");
                    }
                    if (!(searchPrice.getText()).equals("价格/房型")) {
                        String[] date = (searchPrice.getText() + "").split("/");
                        if (date[0].contains("以下")) {
                            intent.putExtra("price", "0," + date[0].split("以")[0]);
                        } else if (date[0].contains("-")) {
                            intent.putExtra("price", date[0].replace("-", ","));
                        } else if (date[0].contains("以上")) {
                            intent.putExtra("price", date[0].split("以")[0]);
                        }


                        intent.putExtra("type", type_num);

                    }

                    startActivity(intent);
                }
                break;
            case R.id.search_location_value:
                if (!(searchAddress.getText() + "").equals("我的附近")) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        requestPermission(permissions, 0x001);
                    } else {
                        mLocationClient.start();

                    }
                    searchAddress.setText("我的附近");
                    searchLocationValue.setTextColor(getResources().getColor(R.color.colorgrey_address));
                    Drawable topDrawable = getResources().getDrawable(R.mipmap.my1);
                    topDrawable.setBounds(0, 0, topDrawable.getMinimumWidth(), topDrawable.getMinimumHeight());
                    searchLocationValue.setCompoundDrawables(null, topDrawable, null, null);
                }
                break;
        }
    }

    @Override
    public void permissionSuccess(int requestCode) {
        super.permissionSuccess(requestCode);
        switch (requestCode) {
            case 0x001:
                mLocationClient.start();
                break;
        }
    }

    private void initLocation() {

        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        //可选，默认高精度，设置定位模式，高精度，低功耗，仅设备

        option.setCoorType("bd09ll");
        //可选，默认gcj02，设置返回的定位结果坐标系

        int span = 1000;
        option.setScanSpan(span);
        //可选，默认0，即仅定位一次，设置发起定位请求的间隔需要大于等于1000ms才是有效的

        option.setIsNeedAddress(true);
        //可选，设置是否需要地址信息，默认不需要

        option.setOpenGps(true);
        //可选，默认false,设置是否使用gps

        option.setLocationNotify(true);
        //可选，默认false，设置是否当GPS有效时按照1S/1次频率输出GPS结果

        option.setIsNeedLocationDescribe(true);
        //可选，默认false，设置是否需要位置语义化结果，可以在BDLocation.getLocationDescribe里得到，结果类似于“在北京天安门附近”

        option.setIsNeedLocationPoiList(true);
        //可选，默认false，设置是否需要POI结果，可以在BDLocation.getPoiList里得到

        option.setIgnoreKillProcess(false);
        //可选，默认true，定位SDK内部是一个SERVICE，并放到了独立进程，设置是否在stop的时候杀死这个进程，默认不杀死

//        option.setIgnoreCacheException(false);
        //可选，默认false，设置是否收集CRASH信息，默认收集

        option.setEnableSimulateGps(false);
        //可选，默认false，设置是否需要过滤GPS仿真结果，默认需要

//        option.setWifiValidTime(5*60*1000);
        //可选，7.2版本新增能力，如果您设置了这个接口，首次启动定位时，会先判断当前WiFi是否超出有效期，超出有效期的话，会先重新扫描WiFi，然后再定位

        mLocationClient.setLocOption(option);
    }

    @Override
    protected void onRestart() {
        super.onRestart();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public class MyLocationListener extends BDAbstractLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {

            //获取定位结果
            latitude = location.getLatitude() + "";    //获取纬度信息
            longitude = location.getLongitude() + "";    //获取经度信息
            Log.e("yyyyyyyyyy", location.getAddrStr());
            city = location.getCity();
//            addressOntime.setText(city + "");
            if (location.getLocType() == BDLocation.TypeGpsLocation) {

                //当前为GPS定位结果，可获取以下信息
                location.getSpeed();    //获取当前速度，单位：公里每小时
                location.getSatelliteNumber();    //获取当前卫星数
                location.getAltitude();    //获取海拔高度信息，单位米
                location.getDirection();    //获取方向信息，单位度
//            location.

            } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {

                //当前为网络定位结果，可获取以下信息
                location.getOperators();    //获取运营商信息

            } else if (location.getLocType() == BDLocation.TypeOffLineLocation) {

                //当前为网络定位结果

            } else if (location.getLocType() == BDLocation.TypeServerError) {

                //当前网络定位失败
                //可将定位唯一ID、IMEI、定位失败时间反馈至loc-bugs@baidu.com

            } else if (location.getLocType() == BDLocation.TypeNetWorkException) {

                //当前网络不通

            } else if (location.getLocType() == BDLocation.TypeCriteriaException) {

                //当前缺少定位依据，可能是用户没有授权，建议弹出提示框让用户开启权限
                //可进一步参考onLocDiagnosticMessage中的错误返回码

            }
        }

        /**
         * 回调定位诊断信息，开发者可以根据相关信息解决定位遇到的一些问题
         * 自动回调，相同的diagnosticType只会回调一次
         *
         * @param locType           当前定位类型
         * @param diagnosticType    诊断类型（1~9）
         * @param diagnosticMessage 具体的诊断信息释义
         */
        public void onLocDiagnosticMessage(int locType, int diagnosticType, String diagnosticMessage) {

            if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_BETTER_OPEN_GPS) {

                //建议打开GPS

            } else if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_BETTER_OPEN_WIFI) {

                //建议打开wifi，不必连接，这样有助于提高网络定位精度！

            } else if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_NEED_CHECK_LOC_PERMISSION) {

                //定位权限受限，建议提示用户授予APP定位权限！

            } else if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_NEED_CHECK_NET) {

                //网络异常造成定位失败，建议用户确认网络状态是否异常！

            } else if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_NEED_CLOSE_FLYMODE) {

                //手机飞行模式造成定位失败，建议用户关闭飞行模式后再重试定位！

            } else if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_NEED_INSERT_SIMCARD_OR_OPEN_WIFI) {

                //无法获取任何定位依据，建议用户打开wifi或者插入sim卡重试！

            } else if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_NEED_OPEN_PHONE_LOC_SWITCH) {

                //无法获取有效定位依据，建议用户打开手机设置里的定位开关后重试！

            } else if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_SERVER_FAIL) {

                //百度定位服务端定位失败
                //建议反馈location.getLocationID()和大体定位时间到loc-bugs@baidu.com

            } else if (diagnosticType == LocationClient.LOC_DIAGNOSTIC_TYPE_FAIL_UNKNOWN) {

                //无法获取有效定位依据，但无法确定具体原因
                //建议检查是否有安全软件屏蔽相关定位权限
                //或调用LocationClient.restart()重新启动后重试！

            }
        }


    }

}
